<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>21.函数生成器：异步获取数据</title>
</head>
<body>
<script>
  function getUser(){
    setTimeout(function () {
      let data = '用户数据'
      //将这次的数据作为yield的结果返回
      iter.next(data)
    },1000)
  }
  function getOrder(){
    setTimeout(function () {
      let data = '订单数据'
      //将这次的数据作为yield的结果返回
      iter.next(data)
    },1000)
  }
  function getItem(){
    setTimeout(function () {
      let data = '商品数据'
      //将这次的数据作为yield的结果返回
      iter.next(data)
    },1000)
  }

  function * f1() {
    let user = yield getUser()
    console.log(user)
    let order = yield getOrder()
    console.log(order)
    let item = yield getItem()
    console.log(item)
  }

  let iter = f1()
  //启动一下这个函数生成器的迭代器
  iter.next()
</script>
</body>
</html>